package com.boot.core.protocol

import com.alibaba.fastjson.JSON
import org.apache.commons.lang3.StringUtils
import java.util.*

class QueryResponseForApp {

    var jsonrpc: String = "2.0"
    var id: String = ""
    var result: QueryResultForApp? = null

    fun QueryResponseForApp(queryResultForApp: QueryResultForApp): Any? {
        this.jsonrpc = this.jsonrpc
        this.id = this.id
        this.result = queryResultForApp
        return this
    }
    fun QueryResponseForApp(queryResponseForApp: QueryResponseForApp): Any? {
        this.jsonrpc = queryResponseForApp.jsonrpc
        this.id = queryResponseForApp.id
        this.result = queryResponseForApp.result
        return this
    }

    fun QueryResponseForApp(data: ArrayList<QueryResultForApp.Data>?, page: QueryResultForApp.Page?, code: Int, msg: String): Any? {
        val sign: String = "singTag"
        this.result = QueryResultForApp(data, page, code, msg, sign)
        return this
    }

    class QueryResultForApp(data: ArrayList<Data>?, page: Page?, code: Int, msg: String, sign: String) {
        var code: Int = code
        var msg: String = msg
        var data: ArrayList<Data>? = data
        var page: Page? = page
        var sign: String = sign

        class Data(sourceId: String?, fieldValues: ArrayList<FieldValues>?) {
            var sourceId: String? = sourceId
            var fieldValues: ArrayList<FieldValues>? = fieldValues

            class FieldValues(field: String?, value: String?, isCode: Int, codeValue: String?) {
                var field: String? = field
                var value: String? = value
                var isCode: Int = isCode
                var codeValue: String? = codeValue
            }
        }

        class Page(pageNo: Int?, pageSize: Int?, total: Long?) {
            var pageSize: Int? = if(pageSize!=null && StringUtils.isNotEmpty(pageSize.toString())) pageSize else 20
            var pageNo: Int? = if(pageNo!=null && StringUtils.isNotEmpty(pageNo.toString())) pageNo else 1
            var total: Long? = total
        }
    }

}